import { Document as l } from '../doc/Document.js';
import { composeNode as N, composeEmptyNode as h } from './compose-node.js';
import { resolveEnd as k } from './resolve-end.js';
import { resolveProps as w } from './resolve-props.js';
function x(d, a, { offset: i, start: m, value: o, end: n }, c) {
  const f = Object.assign({ _directives: a }, d),
    t = new l(void 0, f),
    r = {
      atRoot: !0,
      directives: t.directives,
      options: t.options,
      schema: t.schema,
    },
    e = w(m, {
      indicator: 'doc-start',
      next: o ?? (n == null ? void 0 : n[0]),
      offset: i,
      onError: c,
      startOnNewline: !0,
    });
  e.found &&
    ((t.directives.docStart = !0),
    o &&
      (o.type === 'block-map' || o.type === 'block-seq') &&
      !e.hasNewline &&
      c(
        e.end,
        'MISSING_CHAR',
        'Block collection cannot start on same line with directives-end marker',
      )),
    (t.contents = o ? N(r, o, e, c) : h(r, e.end, m, null, e, c));
  const p = t.contents.range[2],
    s = k(n, p, !1, c);
  return s.comment && (t.comment = s.comment), (t.range = [i, p, s.offset]), t;
}
export { x as composeDoc };
